﻿<%@ WebHandler Language="C#" Class="TypeEditName" %>

using System;
using System.Web;
using System.Data;
using System.Data.Common;
using System.Web.SessionState;

public class TypeEditName : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        /* 管理员信息验证 */
        if (!Admins.IsLogin(true))
            Utils.ShowEnd(context, -2);
        
        /* 外部数据处理 */
        int Id = Convert.ToInt32(context.Request.Params["Id"].ToString());
        string Name = context.Request.Params["Name"].ToString();
        int Orders = Convert.ToInt32(context.Request.Params["Orders"].ToString());

        /* 完整性验证 */
        if (Id < 0)
            Utils.ShowEnd(context, -1);
        if (Orders < 1 || Orders > 255)
            Utils.ShowEnd(context, -1);
        if (Name.Length < 1)
            Utils.ShowEnd(context, -1);
        
        
        
        /*执行*/
        DbParameter[] param = { 
            DBHelper.MakeInParam("@Id",(DbType)SqlDbType.SmallInt,2,Id),
            DBHelper.MakeInParam("@Orders",(DbType)SqlDbType.TinyInt,1,Orders),
            DBHelper.MakeInParam("@Name",(DbType)SqlDbType.NVarChar,150,Name)
        };
        context.Response.Write(DBHelper.ExecuteNonQuery(CommandType.Text, "UPDATE [Types] SET [Name]=@Name,[Orders]=@Orders WHERE [Id]=@Id", param));
        
        
        
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}